import sushidiscount.*
import org.springframework.security.core.context.SecurityContextHolder as SCH

class BootStrap {

    def grailsApplication
    def springSecurityService

    def init = { servletContext ->
        new SushiPlace(name:"Sakura Express",address:"Los Trapenses 10531").save()
        new SecUser(username:"admin",password:"12345",enabled:"true",accountExpired:"false",accountLocked:"false",passwordExpired:"false").save()

        for (cc in grailsApplication.controllerClasses) {
         cc.metaClass.getAuthenticatedUser = { ->
            if (!springSecurityService.isLoggedIn()) return null
            SecUser.findByUsername SCH.context.authentication.principal.username
            }
         }

    }
    def destroy = {
    }
    
    
}
